namespace Organizer.Server.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class rewrite : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Wishes",
                c => new
                    {
                        WishId = c.Int(nullable: false, identity: true),
                        ItemId = c.Int(nullable: false),
                        Name = c.String(),
                        Inserted = c.DateTime(nullable: false),
                        Updated = c.DateTime(nullable: false),
                        IMDb_MovieId = c.Int(),
                    })
                .PrimaryKey(t => t.WishId)
                .ForeignKey("dbo.Movies", t => t.IMDb_MovieId)
                .Index(t => t.IMDb_MovieId);
            
            CreateTable(
                "dbo.Movies",
                c => new
                    {
                        MovieId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Rating = c.Double(nullable: false),
                        Year = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.MovieId);
            
            CreateTable(
                "dbo.People",
                c => new
                    {
                        PersonId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Movie_MovieId = c.Int(),
                        Movie_MovieId1 = c.Int(),
                    })
                .PrimaryKey(t => t.PersonId)
                .ForeignKey("dbo.Movies", t => t.Movie_MovieId)
                .ForeignKey("dbo.Movies", t => t.Movie_MovieId1)
                .Index(t => t.Movie_MovieId)
                .Index(t => t.Movie_MovieId1);
            
            CreateTable(
                "dbo.CharacterPersons",
                c => new
                    {
                        CharacterPersonId = c.Int(nullable: false, identity: true),
                        Person_PersonId = c.Int(),
                        Character_CharacterId = c.Int(),
                        Movie_MovieId = c.Int(),
                    })
                .PrimaryKey(t => t.CharacterPersonId)
                .ForeignKey("dbo.People", t => t.Person_PersonId)
                .ForeignKey("dbo.Characters", t => t.Character_CharacterId)
                .ForeignKey("dbo.Movies", t => t.Movie_MovieId)
                .Index(t => t.Person_PersonId)
                .Index(t => t.Character_CharacterId)
                .Index(t => t.Movie_MovieId);
            
            CreateTable(
                "dbo.Characters",
                c => new
                    {
                        CharacterId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.CharacterId);
            
            DropTable("dbo.Items");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.Items",
                c => new
                    {
                        ItemId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.ItemId);
            
            DropIndex("dbo.CharacterPersons", new[] { "Movie_MovieId" });
            DropIndex("dbo.CharacterPersons", new[] { "Character_CharacterId" });
            DropIndex("dbo.CharacterPersons", new[] { "Person_PersonId" });
            DropIndex("dbo.People", new[] { "Movie_MovieId1" });
            DropIndex("dbo.People", new[] { "Movie_MovieId" });
            DropIndex("dbo.Wishes", new[] { "IMDb_MovieId" });
            DropForeignKey("dbo.CharacterPersons", "Movie_MovieId", "dbo.Movies");
            DropForeignKey("dbo.CharacterPersons", "Character_CharacterId", "dbo.Characters");
            DropForeignKey("dbo.CharacterPersons", "Person_PersonId", "dbo.People");
            DropForeignKey("dbo.People", "Movie_MovieId1", "dbo.Movies");
            DropForeignKey("dbo.People", "Movie_MovieId", "dbo.Movies");
            DropForeignKey("dbo.Wishes", "IMDb_MovieId", "dbo.Movies");
            DropTable("dbo.Characters");
            DropTable("dbo.CharacterPersons");
            DropTable("dbo.People");
            DropTable("dbo.Movies");
            DropTable("dbo.Wishes");
        }
    }
}
